# Maintainer: Alexey Pavlov <alexpux@gmail.com>

_realname=glib-networking
pkgbase=mingw-w64-${_realname}
pkgname="${MINGW_PACKAGE_PREFIX}-${_realname}"
pkgver=2.56.1
pkgrel=1
pkgdesc="Network-related GIO modules for glib (mingw-w64)"
arch=(any)
url="https://download.gnome.org/sources/libsoup"
license=("LGPL")
makedepends=("${MINGW_PACKAGE_PREFIX}-meson"
             "${MINGW_PACKAGE_PREFIX}-ninja"
             "${MINGW_PACKAGE_PREFIX}-gdk-pixbuf2"
             "${MINGW_PACKAGE_PREFIX}-pkg-config"
             "intltool")
depends=("${MINGW_PACKAGE_PREFIX}-gcc-libs"
         "${MINGW_PACKAGE_PREFIX}-gettext"
         "${MINGW_PACKAGE_PREFIX}-glib2"
         "${MINGW_PACKAGE_PREFIX}-gnutls"
         "${MINGW_PACKAGE_PREFIX}-libgcrypt"
         "${MINGW_PACKAGE_PREFIX}-p11-kit"
         "${MINGW_PACKAGE_PREFIX}-xz")
options=('staticlibs' 'strip')
source=("https://download.gnome.org/sources/${_realname}/${pkgver%.*}/${_realname}-${pkgver}.tar.xz"
        0002-relative-system-ca-file.mingw.patch)
sha256sums=('df47b0e0a037d2dcf6b1846cbdf68dd4b3cc055e026bb40c4a55f19f29f635c8'
            'adb974f425095b82bcc1436405833c187e406a7dec2fee474b53b702bbea49fd')

prepare() {
  cd "${srcdir}/${_realname}-${pkgver}"

  patch -p1 -i ${srcdir}/0002-relative-system-ca-file.mingw.patch
}

build() {
  [[ -d "${srcdir}/build-${MINGW_CHOST}" ]] && rm -rf "${srcdir}/build-${MINGW_CHOST}"
  mkdir -p "${srcdir}/build-${MINGW_CHOST}"
  cd build-${MINGW_CHOST}

  meson \
    --buildtype plain \
    -Dca_certificates_path=ssl/certs/ca-bundle.crt \
    -Dpkcs11_support=true \
    -Dlibproxy_support=false \
    -Dgnome_proxy_support=false \
    ../${_realname}-${pkgver}

  ninja
}

package() {
  cd "${srcdir}/build-${MINGW_CHOST}"
  DESTDIR=${pkgdir}${MINGW_PREFIX} ninja install
  rm -f ${pkgdir}${MINGW_PREFIX}/lib/gio/modules/*.a

  install -Dm644 "${srcdir}/${_realname}-${pkgver}/COPYING" "${pkgdir}${MINGW_PREFIX}/share/licenses/${_realname}/COPYING"
}
